<template>
  <div class="home-box">
    <Header></Header>
    <div class="wind-1240" v-if="indexData">
      <div class="header-box">
        <div class="serachLibrary">
          <label class="edit-teaching-packa-img" style="position: relative">
            <Video :url="indexData.coverVideo"></Video>
          </label>
          <div class="teaching-packa-info">
            <div class="teaching-packa-info-name">{{ indexData?.title }}</div>
            <div class="edit-teaching-package-user">
              <div class="user-info-box">
                <div class="usr-box zhu-usr-box">
                  <div class="user-info">
                    <div class="user-name-box">
                      <div class="user-name">{{ principal?.name }}</div>
                      <div class="user-position">
                        {{ principal?.introduce }}
                      </div>
                    </div>
                    <img
                      src="/public/img/teacher1.png"
                      class="user-img"
                      width="40"
                      height="40"
                    />
                  </div>
                </div>
                <div class="usr-box" style="flex: 1">
                  <div
                    class="user-info"
                    v-for="(item, index) in teacherList"
                    :key="index"
                  >
                    <div class="user-name-box">
                      <div class="user-name">{{ item?.name }}</div>
                      <div class="user-position">{{ item.introduce }}</div>
                    </div>
                    <img
                      v-if="index === 0"
                      src="/public/img/teacher2.png"
                      class="user-img"
                      width="40"
                      height="40"
                    />
                    <img
                      v-if="index === 1"
                      src="/public/img/teacher3.png"
                      class="user-img"
                      width="40"
                      height="40"
                    />
                    <img
                      v-if="index === 2"
                      src="/public/img/teacher4.png"
                      class="user-img"
                      width="40"
                      height="40"
                    />
                  </div>
                </div>
              </div>
            </div>
            <div class="usr-box class-info">
              课程说明：{{ indexData?.classIntroduce?.content }}
            </div>
          </div>
        </div>
      </div>
      <div class="tabs-list-box demo-radio-group">
        <div class="tabs-list">
          <div
            :class="`tab-item ${currentTabsKey === item.key ? 'active' : ''}`"
            v-for="(item, i) in tabsList"
            :key="i"
            @click="currentTabsKey = item.key"
          >
            {{ item.title }}
          </div>
        </div>
      </div>
      <div class="tabs-content">
        <CourseIntroduce v-if="currentTabsKey === 'CourseIntroduce'" />

        <KnowledgeMap v-if="currentTabsKey === 'KnowledgeMap'" />
        <ChapterFrame v-if="currentTabsKey === 'ChapterFrame'" />
        <CoursePhilosophy
          v-if="currentTabsKey === 'TeachingCase'"
          title="教学案例"
        />
        <CoursePhilosophy
          v-if="currentTabsKey === 'CoursePhilosophy'"
          title="课程思政"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { useIntersectionObserver } from "@vueuse/core";
import Header from "../components/common/Header.vue";
import CourseIntroduce from "../components/home/CourseIntroduce.vue";
import ChapterFrame from "../components/home/ChapterFrame.vue";
import KnowledgeMap from "../components/home/KnowledgeMap.vue";
import CoursePhilosophy from "../components/home/CoursePhilosophy.vue";
import TeachingCase from "../components/home/TeachingCase.vue";
import Video from "../components/common/Video.vue";
import { ref } from "vue";
const currentTabsKey = ref("");
import { getSubjectData, getIndexData } from "../utils/api/courseManage";
import { storeToRefs } from "pinia";
import { useSubjectStore } from "../store/subject";
const subjectStore = useSubjectStore();
const { addChapterList, addCourseDetail } = storeToRefs(subjectStore);
const indexData = ref(null);
const principal = ref({});
const teacherList = ref([]);
const tabsList = [
  {
    title: "课程介绍",
    key: "CourseIntroduce",
    component: "CourseIntroduce",
  },
  // 章节框架
  {
    title: "章节框架",
    key: "ChapterFrame",
    component: "ChapterFrame",
  },
  // 知识图谱
  {
    title: "知识图谱",
    key: "KnowledgeMap",
    component: "KnowledgeMap",
  },
  // 课程思政
  {
    title: "课程思政",
    key: "CoursePhilosophy",
    component: "CoursePhilosophy",
  },
  // 教学案例
  {
    title: "教学案例",
    key: "TeachingCase",
    component: "TeachingCase",
  },
];
onMounted(() => {
  getIndexData().then((res) => {
    indexData.value = res;
    principal.value = res?.teacher?.filter((item) => item.isPrincipal)[0];
    teacherList.value = res?.teacher?.filter((item) => !item.isPrincipal);
  });
  // 课程分类
  getSubjectData().then((res) => {
    subjectStore.addCourseDetail(res);
    currentTabsKey.value = tabsList[0].key;
  });
});
</script>
<style scope lang="less">
.home-box {
  background: #cbebde;
  min-height: 100vh;
  .wind-1240 {
    width: 1200px;
    margin: 0 auto;
    padding-bottom: 30px;
    * {
      box-sizing: border-box;
    }
  }
  .demo-radio-group {
    width: 100%;
    background: #fff;
    padding: 10px;
    border-radius: 30px;

    .tabs-list {
      display: flex;
      justify-content: space-between;
    }
    .tab-item {
      padding: 10px 36px;
      cursor: pointer;
      &.active {
        background: #d4e8cc;
        color: #217300;
        font-weight: bold;
        border-radius: 25px;
      }
    }
  }
  .tabs-content {
    background: #fff;
    border-radius: 20px;
    margin-top: 20px;
    overflow: hidden;
    min-height: 500px;
  }
}

.teaching-center {
  display: flex;
  min-height: 60vh;
  justify-content: space-between;
  padding: 0;
  background-color: transparent;
  padding-bottom: 20px;
}
.left-teaching-center-con {
  width: 100%;
  height: 100%;
  /*padding-top:15px;*/
  border-radius: 5px;
  box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.1);
}

/* 头部start */
.header-box {
  display: flex;
  position: relative;
  margin: 10px auto;
  text-align: left;
  overflow: hidden;
  .teaching-packa-img {
    width: 120px;
    height: 100px;
    margin-left: 10px;
    cursor: pointer;
  }
  .serachLibrary {
    padding: 40px 0;
    border-radius: 5px;
    width: 100%;
    height: 100%;
    display: flex;
  }
  .teaching-packa-info {
    flex: 1.3;
    margin: 0 20px;
    width: 400px;

    .teaching-packa-info-name {
      font-size: 26px;
      font-weight: 700;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .belong-to-department {
      font-size: 14px;
      line-height: 20px;
      height: 40px;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
  .usr-box {
    background: #b3dcb4;
    display: flex;

    border-radius: 10px;
    &.zhu-usr-box {
      margin-right: 10px;
    }
  }
  .class-info {
    margin-top: 10px;
    font-size: 12px;
    color: #555355;
    font-weight: bold;
    padding: 10px 20px;
    word-break: break-all;
    min-height: 80px;
  }
  .edit-teaching-package-user {
    .user-info-box {
      display: flex;
      font-size: 12px;
      margin-top: 20px;

      .user-info {
        display: flex;
        align-items: center;
        padding: 10px 20px;
        .user-img {
          border-radius: 50%;
        }
        .user-name-box {
          flex: 1;
          text-align: center;
          margin-right: 10px;
          .user-name {
            font-size: 16px;
            font-weight: 700;
          }
          .user-position {
            font-size: 12px;
            color: #555355;
            font-weight: bold;
            margin-top: 5px;
          }
        }
      }
    }
  }
}

.right-teaching-package-info {
  flex: 1;
  padding-left: 10px;
  font-size: 14px;
  text-align: left;
  & > div {
    height: 30px;
    line-height: 30px;
  }
}
.teaching-package-state {
  position: absolute;
  top: 25px;
  right: -43px;
  width: 184px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  transform: rotate(40deg);
  background-color: #ff740e;
  color: #fff;
  & > span {
    display: inline-block;
  }
}
/* 头部end */
/* 修改教学包图片 */
.edit-teaching-packa-img {
  display: block;
  position: relative;
  margin-bottom: 0;
  width: 380px;
  video {
    width: 100%;
  }
}
</style>
